from PyQt4.QtGui import *
from PyQt4.QtCore import *
import sys

class MainWindow (QMainWindow):
    closeBtnClicked=pyqtSignal()
    
    def __init__(self,parent=None):
        super(MainWindow,self).__init__(parent)
        #self.setFixedSize(800,800)
     
        
        self.move_animation=QPropertyAnimation(self,"pos")
        self.opacity_animation=QPropertyAnimation(self,"geometry")
        
        self.move(800,800)
        self.move_animation.setStartValue(QPoint(800, 800));
        self.move_animation.setEndValue(QPoint(10, 10));
        self.move_animation.finished.connect(self.print_test)
        
        self.inti_ui()
        self.init_connect()
       # self.init_animation()
    
        
    def closeEvent(self,env):
        print "close button down"   
        self.closeBtnClicked.emit() 
        env.ignore() 
        
    def inti_ui(self):
        self.setWindowTitle("hanson360")
            
    def init_connect(self):
            self.move_animation.setDuration(2000)
            self.opacity_animation.setDuration(1300)
    
            self.move_animation.setEasingCurve(QEasingCurve.OutQuad)
            self.opacity_animation.setEasingCurve(QEasingCurve.OutQuad)
            
            self.closeBtnClicked.connect(self.unFix)
            
            
    def unFix(self):
        print "unfix"
        #self.setMaximumSize(65535, 65535);
        #self.setMinimumSize(0, 0); 
      
        self.move_animation.start();

        
             
    def  init_animation(self):
        #init the close state machine
        closeMachine=QStateMachine()
        close_start=QState(closeMachine)
        close_end=QState(closeMachine)
        close_start.assignProperty(self,"windowOpacity",0)
        close_end.assignProperty(self,"windowOpacity",1)
        closeMachine.setInitialState(close_start)
        #set the close animation
        close_ani=close_start.addTransition(self,SIGNAL("closeBtnClicked"),close_end)
        #close_ani.addAnimation(self.opacity_animation)
        
        moveMachine=QStateMachine()
        move_start=QState(moveMachine)
        move_end=QState(moveMachine)    
        move_start.assignProperty(self,"geometry",self.geometry() )
        move_end.assignProperty(self,"geometry",QRectF(self.geometry().x() / 8, self.geometry().y() / 8,                                                       self.geometry().width() / 8, self.geometry().height() / 8))     
        moveMachine.setInitialState(move_start)

        #move_ani=move_start.addTransition(self,SIGNAL("closeBtnClicked()"),move_end)
        #move_ani.addAnimation(self.move_animation)
   
        moveMachine.start()
        closeMachine.start()
        
    def print_test(self):
        print "hello"
        
app=QApplication(sys.argv) 
hanson360=MainWindow()
hanson360.show()
app.exec_()   